/**
* 左边菜单
*/ 
<template>
  <el-menu default-active="2" :collapse="collapsed" collapse-transition router :default-active="$route.path" unique-opened class="el-menu-vertical-demo" background-color="#303643" text-color="#fff" active-text-color="#ffd04b">
    <div class="logobox">
      <img class="logoimg" src="../assets/logod.png" alt="">
    </div>
    <el-submenu v-for="menu in allmenu" :key="menu.menuId" :index="menu.name">
      <template slot="title">
        <i class="iconfont" :class="menu.icon"></i>
        <span>{{menu.name}}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item v-for="childMenu in menu.list" :index="'/'+childMenu.url" :key="childMenu.menuId">
          <i class="iconfont" :class="childMenu.icon"></i>
          <span>{{childMenu.name}}</span>
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>
<script>
import { ModuleGet } from "../api/user";
export default {
  name: 'leftMenu',
  data() {
    return {
      collapsed: false,
      allmenu: []
    }
  },
  // 创建完毕状态(里面是操作)
  created() {
     this.initMenu();
    // 监听
    this.$root.Bus.$on('toggle', value => {
      this.collapsed = !value
    })
  },
   methods: {

    initMenu() {
        this.userInfo = localStorage.getItem("userdata");
        console.log(this.userInfo);
        const user = JSON.parse(this.userInfo);
        ModuleGet(user.userId).then(res => {
            //测试直接请求本地JSON数据
            // mockNavList().then(res => {
            this.allmenu = res.data.data;
        });
        },

   }
}
</script>
<style scoped lang="scss">

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 240px;
  min-height: 400px;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
  text-align: left;
}
.el-menu-item-group__title {
  padding: 0px;
}
.el-menu-bg {
  background-color: #2E8B57 !important;
}
.el-menu {
  border: none;
}
.logobox {
  height: 40px;
  line-height: 40px;
  color: #2E8B57;
  font-size: 20px;
  text-align: center;
  padding: 20px 0px;
}
.logoimg {
  height: 40px;
}

</style>